/*
 * Copyright (c) 2009, Hamish Morgan
 * All rights reserver.
 */
package locusts.common.behaviours;

import java.util.Random;

import javax.vecmath.Vector2d;

import locusts.common.entities.Vehicle;

/**
 * Steer in a random direction. Update the heading at irregular intervals.
 * 
 * @author Hamish Morgan
 */
public class WanderBehaviour extends AbstractBehaviour {

    private static final Random rand = new Random();

    /**
     * @param weight
     */
    public WanderBehaviour(double weight) {
        super(weight);
    }

    /**
     *
     */
    public WanderBehaviour() {
        super();
    }

    /*
     * (non-Javadoc)
     * 
     * @see behaviours.Behaviour#getSteering(flock.Vehicle)
     */
    public Vector2d getSteering(Vehicle boid) {

        if (getWeight() == 0d)
            return new Vector2d();

        Vector2d steering = new Vector2d(rand.nextDouble() * 2d - 1d,
                rand.nextDouble() * 2d - 1d);
        steering.normalize();
	steering.scale(getWeight());
        return steering;
    }
}
